package com.xunwulian.base.util;

import com.xunwulian.base.entity.User;

/**
 * Created by liyankai on 2017/3/13.
 */
public class UserUtil {

    public static final String ADMIN_CODE = "1";

    public static final String SUB_ADMIN_CODE = "2";

    public static final String COOPER_CODE = "4";

    public static final String SUBUSER_CODE = "5";

    /***
     * 判断账号是否为子管理员类型账号
     */
    public static boolean isSubAdmin(String roleId) {
        if (roleId != null && (SUB_ADMIN_CODE.contains(roleId))) {
            return true;
        }

        return false;
    }


    /***
     * 判断账号是否为管理员类型账号
     */
    public static boolean isAdmin(String roleId) {
        if (roleId != null && (ADMIN_CODE.contains(roleId))) {
            return true;
        }

        return false;
    }

    public static boolean isAdmin(User user) {
        return isAdmin(user.getROLE_ID()) || isSubAdmin(user.getROLE_ID());
    }


    /**
     * 判断是否具有授权权限
     *
     * @param father
     * @param child
     * @return
     */
    public static boolean hasAuthRight(User father, User child) {
        if (UserUtil.isAdmin(father)) {
            return true;
        } else {
            return child.getParentId() != null && child.getParentId().equals(father.getUSER_ID());
        }
    }


    /***
     * 判断账号是否为企业账号
     */
    public static boolean isCooper(String roleId, String roleParentId) {

        if (roleId != null && (UserUtil.COOPER_CODE.contains(roleId))) {
            return true;
        }

        if (roleId != null && UserUtil.COOPER_CODE.contains(roleParentId)) {
            return true;
        }

        return false;
    }


}
